<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>学生数据列表</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 0;
            padding: 20px;
        }

        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
        }

        th, td {
            border: 1px solid #ddd;
            padding: 8px;
            text-align: left;
        }

        th {
            background-color: #f2f2f2;
        }

        tr:nth-child(even) {
            background-color: #f9f9f9;
        }

        tr:hover {
            background-color: #f1f1f1;
        }

        h1 {
            color: #333;
        }
    </style>
</head>
<body>
    <h1>学生数据列表</h1>
    <table id="studentsTable">
        <thead>
            <tr>
                <th>姓名</th>
                <th>年龄</th>
                <th>专业</th>
                <th>年级</th>
            </tr>
        </thead>
        <tbody>
            <!-- 学生数据将通过JavaScript动态插入 -->
        </tbody>
    </table>

    <script>
        document.addEventListener('DOMContentLoaded', function() {
            var xhr = new XMLHttpRequest();
            xhr.open('GET', 'http://localhost:3000/students', true);
            xhr.onload = function() {
                if (this.status === 200) {
                    var students = JSON.parse(this.responseText);
                    var tableBody = document.getElementById('studentsTable').getElementsByTagName('tbody')[0];
                    students.forEach(function(student) {
                        var row = tableBody.insertRow();
                        row.insertCell(0).textContent = student.name;
                        row.insertCell(1).textContent = student.age;
                        row.insertCell(2).textContent = student.major;
                        row.insertCell(3).textContent = student.grade;
                    });
                } else {
                    console.error('Failed to fetch students data');
                }
            };
            xhr.onerror = function() {
                console.error('Request error...');
            };
            xhr.send();
        });
    </script>
</body>
</html>